<?php
/* Class     Dacap
 * Summary   Get all children customer 
 * @property $visited : array children customer 
 * @author 	 trint
 * @create   10/09/2014
 */

class Dacap {
	private $config;
	private $db;
	private $data = array();
	public $visited = array();
	
	public function __construct($registry) {
		$this->config = $registry->get('config');
		$this->customer = $registry->get('customer');
		$this->currency = $registry->get('currency');
		$this->session = $registry->get('session');
		$this->db = $registry->get('db');
	}
	
	public function dfs($customer_id){
		$customer_parents = array();
		$customer_parents = $this->db->query("SELECT *,ch.price as price2 FROM " . DB_PREFIX . "customer c JOIN customer_info cf ON c.customer_id=cf.customer_id JOIN customer_history ch ON c.customer_id=ch.customer_id WHERE c.customer_parent = '" . (int)$customer_id . "' AND status = '1'")->rows;
		if(count($customer_parents) ==0) {
			return ;
		}
		else if($customer_parents){
			foreach ($customer_parents as $customer_parent){
				$this->visited[] = array(
					'customer_id'     => $customer_parent['customer_id'],
					'name'     		  => $customer_parent['name'],
					'level1'          => $customer_parent['level1'],
					'level2'          => $customer_parent['level2'],
					'index_value1'    => $customer_parent['index_value1'],
					'index_value2'    => $customer_parent['index_value2'],
					'price'           => $this->currency->format($customer_parent['price']),
					'price2'           => $this->currency->format($customer_parent['price2']),
					'customer_parent' => $customer_parent['customer_parent'],
					'date_added'      => date("d-m-Y", strtotime($customer_parent['date_added']))
				);	
				$this->dfs($customer_parent['customer_id']);
			}
		}
		return $this->visited;
	}	
}
?>